package service;

import java.sql.SQLException;
import java.util.List;

import dao.OwnerDaoImpl;
import domain.Owner;
import domain.Pet;

public class OwnerServiceImpl {
	//创建OwnerDaoImpl对象
	OwnerDaoImpl ownerDao = new OwnerDaoImpl();
	
	/**
	 * 查询所有宠物主人信息
	 * @return
	 */
	public List<Owner> findAllOwners(){
		try {
			return ownerDao.findAllOwners();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	/**
	 * 添加一条宠物主人信息
	 * @param owner
	 */
	public void addOwner(Owner owner){
		try {
			ownerDao.addOwner(owner);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 通过宠物id查找宠物主人信息
	 * @param id
	 * @return
	 */
	public Owner findOwnerById(String ownerId) {
		try {
			return ownerDao.findOwnerById(ownerId);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	/**
	 * 更新宠物主人信息
	 * @param owner
	 */
	public void updateOwner(Owner owner) {
		try {
			ownerDao.updateOwner(owner);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public List<Pet> findPetsByOwnerId(String ownerId) {
		try {
			return ownerDao.findPetsByOwnerId(ownerId);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}
	/**
	 * 通过ownerId删除主人信息
	 * @param ownerId
	 * @return
	 */
	public void deleteOwnerById(String ownerId) {
		try {
			ownerDao.deleteOwnerById(ownerId);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public List<Owner> findOwnerByConditions(String ownerId, String ownerName,
		String ownerAddress, String ownerCity, String ownerPhone) {
		try {
			return ownerDao.findOwnerByConditions(ownerId, ownerName, ownerAddress, ownerCity, ownerPhone);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	
	
}
